import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    const token = ref('')
    const userInfo = ref({})

    const isLogin = computed(() => !!token.value)

    function login(userData) {
      token.value = userData.token || ''
      userInfo.value = userData
    }

    function logout() {
      token.value = ''
      userInfo.value = {}
    }

    return { token, userInfo, isLogin, login, logout }
  },
  {
    persist: true
  }
)
